package com.factory.websocket;

import javax.websocket.Session;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class SessionListUtis {


    private static ConcurrentHashMap<String, List<Session>> sessionPools = new ConcurrentHashMap<>();


    public static ConcurrentHashMap<String, List<Session>> getAll() {
        return sessionPools;
    }

    public static List<Session> getHashMap(String user) {
        return sessionPools.get(user);
    }

    public static void setHashMap(String userid, List<Session> sessions) {
        sessionPools.put(userid, sessions);

    }

    public static void remove(String user, Session session) {
        List<Session> sessions = sessionPools.get(user);
        for (int i = 0; i < sessions.size(); i++) {
            if (sessions.get(i) == session) {
                sessions.remove(i);
            }
        }
    }
}
